package com.atguigu.boot.admin.controller;


import com.atguigu.boot.admin.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class AdminController {


    @GetMapping(value = {"/","/login"})
    public String loginPage(){

        return "login";
    }



    @GetMapping("/main.html")
    public String mainPage(){

        return "main";
    }

    @PostMapping("/login")
    public String main(User user, HttpSession session, Model model){

        if (StringUtils.hasText(user.getUserName()) && StringUtils.hasLength(user.getPassword())){
            session.setAttribute("login",user);
            return "redirect:/main.html";
        }
        return "login";

    }
}
